// 定义日期的天数计算
function dayComputed(date1,date2){
	const datebeg = new Date(date1.replace(/-/g, '/')); // 有些浏览器可能不支持"YYYY-MM-DD"格式，所以替换为"YYYY/MM/DD"
	const dateend = new Date(date2.replace(/-/g, '/'));
	// 计算时间戳的差值（毫秒）
	const timeDifference = (dateend - datebeg);
	// 将毫秒数转换为天数
	const daysDifference = Math.round(timeDifference / (1000 * 60 * 60 * 24));
	return daysDifference;
}
// 定义日期的天数计算
function durationRateComputed(beg,end){
	if(beg == end)
	{
		return 0;
	}
	// 获取当前日期
	const currentDate = new Date();
	// 提取年份、月份和日期
	const year = currentDate.getFullYear();
	const month = String(currentDate.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以需要+1，并且用padStart补零
	const day = String(currentDate.getDate()).padStart(2, '0'); // 用padStart补零
	// 格式化日期为 YYYY-MM-DD
	let today = `${year}-${month}-${day}`;
	let duration = dayComputed(beg,end);
	let nowduration = dayComputed(beg,today);
	if (nowduration < 0)
	{
		nowduration = 0;
	}
	const rate = nowduration/duration;
	return Math.ceil(rate*100);
}
// 计算剩余天数
function RemianingDaysComputed(beg,end){
	// 获取当前日期
	const currentDate = new Date();
	// 提取年份、月份和日期
	const year = currentDate.getFullYear();
	const month = String(currentDate.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以需要+1，并且用padStart补零
	const day = String(currentDate.getDate()).padStart(2, '0'); // 用padStart补零
	// 格式化日期为 YYYY-MM-DD
	let today = `${year}-${month}-${day}`;
	let duration = dayComputed(beg,end);
	let nowduration = dayComputed(beg,today);
	if (nowduration < 0){
		nowduration = 0;
	}
	if(duration-nowduration<0){
		return 0;
	}
	return duration-nowduration;
}
// 计算当前天数
function todayString(){
	// 获取当前日期
	const currentDate = new Date();
	// 提取年份、月份和日期
	const year = currentDate.getFullYear();
	const month = String(currentDate.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以需要+1，并且用padStart补零
	const day = String(currentDate.getDate()).padStart(2, '0'); // 用padStart补零
	// 格式化日期为 YYYY-MM-DD
	let today = `${year}-${month}-${day}`;
	return today;
}
export default {
	durationRateComputed:durationRateComputed, 	// 导出比例计算
	dayComputed:dayComputed, 					// 导出日期间隔计算
	RemianingDaysComputed:RemianingDaysComputed,// 导出剩余天数计算
	todayString:todayString,					// 导出当前天的日期
};